<template>
  <view v-if="!isOldStyle" class="hot-service" :style="`${styles}`">
    <view class="hot-service-title">热门服务</view>

    <view class="hot-service-list">
      <template v-for="(item, index) in listData" :key="index">
        <view v-if="!item.name.includes('一件事')" class="hot-service-list-item" @click="handleItemClick(item)">
          <svg v-if="!item.icon.includes('http')" class="icon" aria-hidden="true">
            <use :xlink:href="'#' + item.icon" />
          </svg>
          <img v-else :src="item.icon" alt="" class="icon">
          <text>{{ item.alias ? item.alias : item.name }}</text>
        </view>
      </template>

    </view>

    <view class="hot-service-zcjy" v-if="listData.findIndex((val) => { return val.name.includes('一件事') })"
      :style="{ 'background': listData.filter((val) => { return val.name.includes('一件事') })[0].bgcolor }"
      @click="handleItemClick(listData.filter((val) => { return val.name.includes('一件事') })[0].url)">
      <view class="hot-service-zcjy-left">
        <view>{{ listData.filter((val) => { return val.name.includes('一件事') })[0].name }}</view>
        <view>
          <text>跨部门事项一次办</text>
          <view>点击查看 ></view>
        </view>
      </view>
      <svg v-if="!listData.filter((val) => { return val.name.includes('一件事') })[0].bgimage.includes('http')"
        class="hot-service-zcjy-right" aria-hidden="true">
        <use :xlink:href="'#' + listData.filter((val) => { return val.name.includes('一件事') })[0].bgimage" />
      </svg>
      <img v-else class="hot-service-zcjy-right"
        :src="listData.filter((val) => { return val.name.includes('一件事') })[0].bgimage" alt="">

    </view>
  </view>

  <view v-if="isOldStyle" class="old-hot-service" style="margin-bottom:20px">
    <view class="hot-service-title">热门服务</view>

    <view class="hot-service-list">
      <template v-for="(item, index) in listData" :key="index">
        <view v-if="!item.name.includes('一件事')" class="hot-service-list-item" @click="handleItemClick(item)">
          <svg v-if="!item.icon.includes('http')" class="icon" aria-hidden="true">
            <use :xlink:href="'#' + item.icon" />
          </svg>
          <img v-else :src="item.icon" alt="" class="icon">
          <text>{{ item.alias ? item.alias : item.name }}</text>
        </view>
      </template>

    </view>

    <view class="hot-service-zcjy" v-if="listData.findIndex((val) => { return val.name.includes('一件事') })"
      :style="{ 'background': listData.filter((val) => { return val.name.includes('一件事') })[0].bgcolor }"
      @click="handleItemClick(listData.filter((val) => { return val.name.includes('一件事') })[0].url)">
      <view class="hot-service-zcjy-left">
        {{ listData.filter((val) => { return val.name.includes('一件事') })[0].name }}
      </view>
    </view>

  </view>


  <view v-if="isOldStyle" class="old-hot-service" style="margin-top:20px;">
    <view class="hot-service-title">线上一站办</view>
    <view class="hot-service-list">
      <view class="hot-service-list-item" v-for="(item, index) in onlineThingList" :key="index"
        @click="handleClickMore(item)">
        <img :src="item.img" alt="">
        <text>{{ item.alias ? item.alias : item.name }}</text>
      </view>
    </view>
  </view>
</template>


<script lang="ts" setup>
import { ref } from "vue";


const props = defineProps({
  styles: String,
  isOldStyle: Boolean,
  matterList: Array
})


const listData = ref([

])

listData.value = props.matterList.filter((val) => {
  return val.type.includes('5')
})

let styles = ref('')
if (props.styles) {
  styles.value = props.styles?.replace(/"/g, '');
}



const emit = defineEmits(['handleClick', 'handleClickMore'])
const handleItemClick = (item) => {
  emit('handleClick', {
    url: item.url,
    content: item.name
  })
}

const onlineThingList = ref([
  { name: '残疾人证办理', img: `https://zjcl-ywpt.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/zlb-zhzc/zhzc-hotService-card.png`, type: 'cardThing' },
  { name: '补贴与减免', img: `https://zjcl-ywpt.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/zlb-zhzc/zhzc-hotService-life.png`, type: 'btyjm' },
  { name: '社会保障', img: `https://zjcl-ywpt.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/zlb-zhzc/zhzc-hotService-nurse.png`, type: 'shbz' },
  { name: '残疾人出行', img: `https://zjcl-ywpt.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/zlb-zhzc/zhzc-hotService-allowance.png`, type: 'travel' },
  { name: '就创业一件事', img: `https://zjcl-ywpt.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/zlb-zhzc/zhzc-hotService-life.png`, type: 'jcy' },
  { name: '特色服务', img: `https://zjcl-ywpt.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/zlb-zhzc/zhzc-hotService-nurse.png`, type: 'facility' },
])

const handleClickMore = (item: String) => {
  emit('handleClickMore', {
    type: item.type
  })
}

</script>


<style lang="scss" scoped>
.hot-service {
  width: 650upx;
  height: auto;
  border-radius: 12px;
  background-color: #ffffff;
  color: rgba(16, 16, 16, 1);
  font-size: 14px;
  margin: 0 auto;
  margin-top: 24upx;
  position: relative;
  overflow: hidden;
  padding: 20upx;

  .hot-service-title {
    color: rgba(54, 58, 68, 1);
    font-size: 36upx;
    font-weight: bold;
  }

  .hot-service-list {
    display: flex;
    justify-content: space-around;
    margin: 32upx 0;

    .hot-service-list-item {
      display: flex;
      align-items: center;
      flex-direction: column;

      .icon {
        width: 60upx;
        height: 60upx;
      }

      text {
        font-size: 24upx;
        color: #101010;
        margin-top: 14upx;
      }
    }
  }

  .hot-service-zcjy {
    width: calc(100% - 24upx);
    height: 172upx;
    background: #DFEBFF;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12upx 0 24upx;

    .hot-service-zcjy-left {
      display: flex;
      flex-direction: column;

      view:nth-child(1) {
        color: rgba(54, 58, 68, 1);
        font-size: 32upx;
        font-weight: bold;
        margin-bottom: 12upx;
      }

      view:nth-child(2) {
        font-size: 24upx;
        color: rgba(104, 107, 115, 1);
        display: flex;
        align-items: center;

        view {
          width: 156upx;
          height: 40upx;
          line-height: 40upx;
          border-radius: 12px;
          background-color: rgba(215, 238, 255, 1);
          color: rgba(87, 144, 226, 1);
          font-size: 24upx;
          text-align: center;
          justify-content: center;
          margin-left: 12upx;
        }
      }
    }

    .hot-service-zcjy-right {
      width: 226upx;
      height: 170upx;
    }
  }
}

.old-hot-service {
  width: 650upx;
  height: auto;
  border-radius: 12px;
  background-color: #ffffff;
  color: rgba(16, 16, 16, 1);
  font-size: 18px;
  margin: 0 auto;
  margin-top: -200upx;
  position: relative;
  overflow: hidden;
  padding: 20upx;

  .hot-service-title {
    font-size: 24px;
    color: #101010;
    font-weight: bold;
    text-align: center;
    margin: 0px auto;
  }

  .hot-service-list {
    display: flex;
    justify-content: space-around;
    margin: 32upx 0;
    flex-wrap: wrap;

    .hot-service-list-item {
      display: flex;
      align-items: center;
      flex-direction: column;
      width: 50%;
      margin-top: 20px;

      .icon {
        width: 56px;
        height: 56px;
      }

      text {
        font-size: 20px;
        color: #101010;
        margin-top: 8upx;
        font-weight: bold;
      }
    }
  }

  .hot-service-zcjy {
    width: calc(100% - 24upx);
    height: 86px;
    background: #DFEBFF;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;

    .hot-service-zcjy-left {
      width: 80%;
      height: 44px;
      border-radius: 25px;
      background: #5790E2;
      color: #ffffff;
      font-size: 20px;
      font-weight: bold;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}</style>